const fs = require('fs')
const path = require('path')
const Mock = require('mockjs')
const JSON5 = require('json5')
// 读取json文件
function getJsonFile(filepath){
  let json = fs.readFileSync(path.resolve(__dirname,filepath), 'utf-8');
  return JSON5.parse(json);
}

// 设置路由，一个服务器的路由
module.exports = function (app){
  if(process.env.MOCK == 'true'){
    app.get('/user/userinfo',function (req, res){
      let json = getJsonFile('./userInfo.json5');
      res.json(Mock.mock(json))
    })
  }
}
